package WinterFlower.work0716;

import java.util.Random;


public class StringBufferEX01 {
    public static void main(String[] args) {

        Random random = new Random();

        String letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        long millis = System.currentTimeMillis();
        System.out.println(millis);

        StringBuffer sbf = new StringBuffer(String.valueOf(millis));//millis +"";

        int insertIndex = 2;
        for (int i = 1; i <= 5; i++) {
            sbf.insert(insertIndex, letters.charAt(random.nextInt(letters.length())));
            insertIndex += 3;
        }

        System.out.println(sbf.toString());


        String str = "iu38sdsv73xcwe7y";
        StringBuffer sbf2 = new StringBuffer(str);
        StringBuffer num = new StringBuffer();//存放每一个字符整数

        for (int i = 0; i < sbf2.length(); i++) {

            char ci = sbf2.charAt(i);
            if (Character.isDigit(ci)) {
                num.append(ci);
            }

        }
        int i = Integer.parseInt(num.toString());
        System.out.println(i);


        /**
         * String ,StringBuffer ,StringBuilder
         * String 是固定长度字符串，原因内部保存字符的数组是 final修饰 本质是常量
         * StringBuffer,StringBuilder 是可变长度字符串，原因内部保存字符的数组不是 final 修饰，可以重新指向数组
         * StringBuffer 是线程安全的
         * StringBuilder 是线程不安全的
         * StringBuffer 和 StringBuilder API 是一样的
         * String << StringBuffer < StringBuilder
         *
         *
         *
         */
    }
}
